package com.itheima.controller;

import com.itheima.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

/*****
 * @Author: 黑马训练营
 * @Description: com.itheima.controller
 ****/
@Controller
@RequestMapping(value = "/test")
public class TestController {

    /***
     * 测试
     */
    @RequestMapping(value = "/hello")
    public String hello(Model model){
        //输出文本数据
        model.addAttribute("hello","你好！");

        //文本数据
        model.addAttribute("description","今天<span style=\"color:red;\">太阳</span>真大啊!");

        //创建集合，页面输出集合对象
        List<User> users = new ArrayList<User>();
        users.add(new User(1,"张三","深圳"));
        users.add(new User(2,"李四","北京"));
        users.add(new User(3,"王五","武汉"));
        model.addAttribute("users",users);

        //存储一个Date
        model.addAttribute("now",new Date());

        //年龄
        model.addAttribute("age",17);

        //Map
        Map<String,Object> dataMap = new HashMap<String,Object>();
        dataMap.put("No","No001");
        dataMap.put("address","深圳北京天津广州上海");
        model.addAttribute("dataMap",dataMap);

        //判断字符是否以某个特定字符开始
        model.addAttribute("name","spec_深圳");

        //存储一个地址
        model.addAttribute("url","/test/add");
        return "demo1";
    }


    /***
     * /test/add
     */
    @GetMapping(value = "/add")
    public String add(String name,int age){
        System.out.println("name:"+name+",age:"+age);
        return "redirect:http://www.itheima.com";
    }
}
